package com.wzy.service.impl;


import com.wzy.dao.ExternalPopulationDao;

import com.wzy.dao.UndocumentedWorkersDao;
import com.wzy.pojo.ExternalPopulation;
import com.wzy.pojo.UndocumentedWorkers;
import com.wzy.service.ExternalPopulationService;
import com.wzy.service.UndocumentedWorkersService;
import com.wzy.utils.Utils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("undocumentedWorkersService")
public class UndocumentedWorkersServiceImpl implements UndocumentedWorkersService {
    @Autowired
    private ExternalPopulationService externalPopulationService;

    SqlSession sqlSession = Utils.getSqlSession();
    UndocumentedWorkersDao undocumentedWorkersDao  =sqlSession.getMapper(UndocumentedWorkersDao.class);

    @Override
    public UndocumentedWorkers findUndocumentedWorkers(String ID) {
        return null;
    }

    @Override
    public List<UndocumentedWorkers> findUndocumentedWorkersAll() {
        return undocumentedWorkersDao.findUndocumentedWorkersAll();
    }

    @Override
    public boolean addUndocumentedWorkers(UndocumentedWorkers u) {
        if(externalPopulationService.findExternalPopulation(u.getID_number())==null) {
            ExternalPopulation e = new ExternalPopulation();
            e.setID_number(u.getID_number());
            e.setResidential_pass("否");
            System.out.println(e);
            externalPopulationService.addExternalPopulation(e);
            undocumentedWorkersDao.addUndocumentedWorkers(u);
            return true;
        }else {
            return  false;
        }
    }

    @Override
    public void deleteUndocumentedWorkers(String ID) {
        externalPopulationService.deleteExternalPopulation(ID);
        undocumentedWorkersDao.deleteUndocumentedWorkers(ID);

    }

    @Override
    public void updateUndocumentedWorkers(UndocumentedWorkers u) {
        undocumentedWorkersDao.updateUndocumentedWorkers(u);
    }
}
